package com.skydonkey.dao;

import com.github.pagehelper.Page;
import com.skydonkey.pojo.po.VideoMyFavorite;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface VideoMyFavoriteMapper {

    @Insert("INSERT INTO videos_my_favorite (uid, video_id) VALUES (#{uid}, #{videoId})")
    @Options(useGeneratedKeys = true, keyProperty = "recordId")
    int insertMyFavoriteVideo(VideoMyFavorite videoMyFavorite);

    @Delete("DELETE FROM videos_my_favorite WHERE video_id = #{videoId} and uid = #{uid}")
    int deleteMyFavoriteVideoById(VideoMyFavorite videoMyFavorite);

    @Select("SELECT * FROM videos_my_favorite WHERE uid = #{uid} order by create_time ")
    Page<VideoMyFavorite> getFavoriteVideosByUid(Long uid);

    @Select("SELECT COUNT(*) FROM videos_my_favorite WHERE uid = #{uid} AND video_id = #{videoId}")
    int isVideoFavoritedByUser(@Param("uid") Long uid, @Param("videoId") Long videoId);

    @Select("SELECT COUNT(1) FROM videos_my_favorite WHERE video_id = #{videoId}")
    long getVideoMyFavCount(@Param("videoId") Long videoId);

}
